//#define __DEBUG__
// by Tyrghen
#define THIS_FILE "fn_kickplayerbasefiredvehicle.sqf"
#include "x_setup.sqf"

private ["_vehicle","_role","_weapon","_turret_id","_cfgTurrets","_cfgTurret","_ammo","_num"];

_vehicle = _this select 0;
// diag_log format["kickplayerbasefiredvehicle: %1 %2",_this, [assignedVehicleRole player,vehicle player,(_vehicle == vehicle player)]];

if (_vehicle == vehicle player) then {
	if ((serverCommandAvailable "#shutdown") || (if (isnil "mp_rights_fnc_hasRoles") then { false } else { (([] call mp_rights_fnc_isMember)) }) ) then {
		// We ignore admins and team members
	} else {
		// diag_log format["kickplayerbasefiredvehicle: %1",[(player in (list GVAR(player_base_trig))),(_vehicle in (list GVAR(player_base_trig))),(list GVAR(player_base_trig))]];
		if (_vehicle in (list GVAR(player_base_trig))) then {
			_ammo = objNull;
			_role = assignedVehicleRole player;
			_weapon = _this select 1;
			if (count _this > 6) then { _ammo = _this select 6 };
			// diag_log format["kickplayerbasefiredvehicle: %1",[_role, _weapon,_ammo]];
			if (!isnull _ammo) then { deleteVehicle _ammo; };
			if (toUpper(_role select 0) == "TURRET") then {
				_turret_id = (_role select 1) select 0;
				_cfgTurrets = (configfile >> "CfgVehicles" >> (typeof _vehicle) >> "Turrets");
				_cfgTurret = _cfgTurrets select _turret_id;
				_wpn_arr = getArray (_cfgTurret >> "weapons");
				// diag_log format["kickplayerbasefiredvehicle: %1",[_wpn_arr,(_weapon in _wpn_arr)]];
				if ((count _wpn_arr) > 0) then {
					if (_weapon in _wpn_arr) then {
						_num = __pGetVar(GVAR(p_f_b));
						__INC(_num);
						__pSetVar [QGVAR(p_f_b), _num];
						if (GVAR(player_kick_shootingbase) != 1000) then {
							if (_num >= GVAR(player_kick_shootingbase)) then {
								if (isNil {__pGetVar(GVAR(pfbk_announced))}) then {
									[QGVAR(p_f_b_k), [player, GVAR(name_pl),0]] call FUNC(NetCallEventCTS);
									__pSetVar [QGVAR(pfbk_announced), true];
								};
							} else {
								hint (localize "STR_DOM_MISSIONSTRING_537");
							};
						} else {
							if (_num >= GVAR(player_kick_shootingbase)) then {
								[QGVAR(p_bs), [player, GVAR(name_pl),0]] call FUNC(NetCallEventCTS);
							};
						};
					};
				};
			};
		} else {
			__pSetVar [QGVAR(p_f_b), 0];
		};
	};
};
